/**
 * LockboxItem
 * Secret Item class
 *
 * Created by Nathan Black
 */
 
#import "LockboxItem.h"

@implementation LockboxItem

-initWithType:(enum LockboxItemType)_type
{
    if ((self = [super init])) {
        type = _type;
        // manage the MutableArray, but not the items - autorelease them.
        tags = [[[NSMutableArray alloc] init] retain];
    }
    return self;
}

-(void)dealloc
{
    [self deallocMembersExceptTags];
    [super dealloc];
    [tags release];
    tags = NULL;
}

-(void)deallocMembersExceptTags
{
    [key release];
    key = NULL;
    [value release];
    value = NULL;
    [note release];
    note = NULL;
    [website release];
    website = NULL;
    [additionalInfo release];
    additionalInfo = NULL;
    [expDate release];
    expDate = NULL;
    [phone1 release];
    phone1 = NULL;
}

- (id)initWithCoder:(NSCoder *)coder 
{ 
  self = [super init]; 
  type = [coder decodeIntForKey:@"type"]; 
  key = [[coder decodeObjectForKey:@"key"] retain]; 
  value = [[coder decodeObjectForKey:@"value"] retain]; 
  note = [[coder decodeObjectForKey:@"note"] retain]; 
  website = [[coder decodeObjectForKey:@"website"] retain]; 
  additionalInfo = [[coder decodeObjectForKey:@"additionalInfo"] retain]; 
  expDate = [[coder decodeObjectForKey:@"expDate"] retain]; 
  phone1 = [[coder decodeObjectForKey:@"phone1"] retain]; 
  tags = [[coder decodeObjectForKey:@"tags"] retain]; 

  return self; 
}

- (void)encodeWithCoder:(NSCoder *)coder 
{ 
  /*NSLog(@"encode: key 0x%08x", key);
  NSLog(@"encode: value 0x%08x", value);
  NSLog(@"encode: note 0x%08x", note);
  NSLog(@"encode: website 0x%08x", website);
  NSLog(@"encode: additionalInfo 0x%08x", additionalInfo);
  NSLog(@"encode: expDate 0x%08x", expDate);
  NSLog(@"encode: phone1 0x%08x", phone1);*/
  [coder encodeInt:type forKey:@"type"]; 
  [coder encodeObject:key forKey:@"key"]; 
  [coder encodeObject:value forKey:@"value"]; 
  [coder encodeObject:note forKey:@"note"]; 
  [coder encodeObject:website forKey:@"website"]; 
  [coder encodeObject:additionalInfo forKey:@"additionalInfo"]; 
  [coder encodeObject:expDate forKey:@"expDate"]; 
  [coder encodeObject:phone1 forKey:@"phone1"]; 
  [coder encodeObject:tags forKey:@"tags"]; 
} 

@end